'''

setStyle()
QstyleFactory()  当前平台支持的样式
QApplication.setStyle()  设置样式

'''
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class AppWidget(QWidget):
    def __init__(self,parent=None):
        super(AppWidget,self).__init__(parent)
        self.setWindowTitle("绘图")
        #pixmap
        self.pix=QPixmap()
        self.lastPoint=QPoint()
        self.endPoint=QPoint()
        self.initUI()
    def initUI(self):
        self.resize(600,600)
        #画布大小
        self.pix=QPixmap(450,450)
        self.pix.fill(Qt.white)
    def paintEvent(self,event):
        pp=QPainter(self.pix)
        #根据鼠标指针前后位置绘制直线
        pp.drawLine(self.lastPoint,self.endPoint)
        #让前一个坐标值等于后一个坐标值
        self.lastPoint=self.endPoint
        painter=QPainter(self)
        #画布指定到窗口指定位置
        painter.drawPixmap(0,0,self.pix)
    def mousePressEvent(self,event):
        #鼠标左键
        if event.button()==Qt.LeftButton:
            self.lastPoint=event.pos()
            self.endPoint=self.lastPoint
    def mouseMoveEvent(self, event):
        #鼠标左键按下的同时移动鼠标
        if event.buttons() and Qt.LeftButton:
            self.endPoint=event.pos()
            self.update()
    def mouseReleaseEvent(self, event):
        if event.button()== Qt.LeftButton:
            self.endPoint=event.pos()
            self.update()

if __name__ == '__main__':
    app=QApplication(sys.argv)
    win=AppWidget()
    win.show()
    sys.exit(app.exec_())